home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DllSys_Files / UNSUPERV / HEBB.C next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  1.8 KB  |  55 lines

  1. // Dynamic link library implementation of NeuroSolutions HebbFull component 
  2.  
  3. #include "NSDLL.h" 
  4.  
  5. /*************************************************************/
  6. /* Macros to access the PE layers and weights in matrix form */
  7.  
  8. #define in(i,j)        input[j+i*inCols]
  9. #define out(i,j)    output[j+i*outCols]
  10. #define W(i,j)        weights[j+i*inCount]
  11.  
  12. /******************************/
  13. /* Unsupervised weight update */
  14.  
  15. __declspec(dllexport) void performUnsupervised(
  16.     DLLData    *instance,    // Pointer to instance data (may be NULL)
  17.     NSFloat    *input,        // Pointer to input layer 
  18.     int     inRows,        // Number of rows of PEs in the input layer
  19.     int     inCols,        // Number of columns of PEs in the input layer
  20.     NSFloat    *output,     // Pointer to the output layer
  21.     int     outRows,    // Number of rows of PEs in the output layer
  22.     int     outCols,    // Number of columns of PEs in the output layer
  23.     NSFloat    *weights,    // Pointer to fully connected weight matrix 
  24.     NSFloat    step         // Learning rate
  25.     )
  26. {
  27.     int    i, j,
  28.         inCount=inRows*inCols,
  29.         outCount=outRows*outCols;
  30.  
  31.     for (j=0; j<inCount; j++)
  32.         for (i=0; i<outCount; i++)
  33.             W(i,j) += step*input[j]*output[i];
  34. }
  35.  
  36. /******************************************/
  37. /* Management of instance data (OPTIONAL) */
  38. /*
  39. __declspec(dllexport) DLLData *allocUnsupervised(
  40.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  41.     int     inRows,        // Number of rows of PEs in the input layer
  42.     int     inCols,        // Number of columns of PEs in the input layer
  43.     int     outRows,    // Number of rows of PEs in the output layer
  44.     int     outCols        // Number of columns of PEs in the output layer
  45.     )
  46. {
  47.     DLLData *instance = allocDLLInstance(oldInstance);
  48.     return instance;
  49. }
  50.  
  51. __declspec(dllexport) void freeUnsupervised(DLLData *instance)
  52. {
  53.     freeDLLInstance(instance);
  54. }
  55. */